﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Common="clr-namespace:MaxAlarm.Common;assembly=MaxAlarm.Common"
                    xmlns:System="clr-namespace:System;assembly=mscorlib"
                    xmlns:ViewModels="clr-namespace:MaxAlarm.ViewModels">



    <DataTemplate x:Key="DefaultAlarmTemplate">
        <Grid HorizontalAlignment="Stretch">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            
            <Grid Grid.Column="0"
                  HorizontalAlignment="Center"
                  VerticalAlignment="Center">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                
                <TextBlock Style="{StaticResource BigWhite}"
                           Text="Type:"
                           VerticalAlignment="Center"
                           HorizontalAlignment="Right"
                           Margin="5" />
                
                <TextBox Style="{StaticResource LoginBox}"
                         VerticalAlignment="Center"
                         HorizontalAlignment="Left"
                         Margin="5"
                         Grid.Column="1"
                         Width="200"
                         x:Name="AlarmName"
                         Text="{Binding Path=Type}"/>
                
            </Grid>

            <Grid Grid.Column="1"
                  HorizontalAlignment="Center"
                  VerticalAlignment="Center">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <TextBlock Style="{StaticResource BigWhite}"
                           Text="Level:"
                           VerticalAlignment="Center"
                           HorizontalAlignment="Right"
                           Margin="5" />

                <ComboBox ItemsSource="{Binding Source={StaticResource AlarmLevelProvider}}"
                          VerticalAlignment="Center"
                          HorizontalAlignment="Left"
                          Margin="5"
                          Grid.Column="1"
                          Height="25"
                          IsEditable="False"
                          IsSynchronizedWithCurrentItem="True"
                          IsTextSearchEnabled="True"
                          SelectedIndex="0"
                          Width="100"
                          SelectedItem="{Binding Path=Level, Mode=TwoWay}"/>

            </Grid>

            <Grid Grid.Column="2"
                  HorizontalAlignment="Center"
                  VerticalAlignment="Center">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <TextBlock Style="{StaticResource BigWhite}"
                           Text="Action:"
                           VerticalAlignment="Center"
                           HorizontalAlignment="Right"
                           Margin="5" />

                <ComboBox ItemsSource="{Binding Source={StaticResource AlarmActionProvider}}"
                          VerticalAlignment="Center"
                          HorizontalAlignment="Left"
                          Margin="5"
                          Grid.Column="1"
                          Height="25"
                          IsEditable="False"
                          IsSynchronizedWithCurrentItem="True"
                          IsTextSearchEnabled="True"
                          SelectedIndex="0"
                          x:Name="SelectedAction"
                          Width="100"
                          SelectedItem="{Binding Path=Action, Mode=TwoWay}"/>

            </Grid>

            <Grid Grid.Column="3"
                  HorizontalAlignment="Center"
                  VerticalAlignment="Center"
                  x:Name="WaitGrid"
                  Visibility="Collapsed">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <TextBlock Style="{StaticResource BigWhite}"
                           Text="Wait:"
                           VerticalAlignment="Center"
                           HorizontalAlignment="Right"
                           Margin="5" />

                <TextBox Style="{StaticResource LoginBox}"
                         VerticalAlignment="Center"
                         HorizontalAlignment="Left"
                         Margin="5"
                         Grid.Column="1"
                         Width="40"
                         x:Name="WaitInterval"
                         Text="{Binding Path=WaitInterval}"/>

            </Grid>

            <StackPanel Orientation="Horizontal"
                        Grid.Row="1"
                        Grid.ColumnSpan="4"
                        Margin="10,20,0,0"
                        VerticalAlignment="Center"
                        HorizontalAlignment="Center">

                <Button Margin="10,0,0,0" 
                        Style="{StaticResource LoginButtons}"
                        x:Name="SaveButton"
                        Command="{x:Static ViewModels:SettingsPageViewModel.SaveNewItemCommand}">
                    <Button.Content>
                        <TextBlock Text="Save" 
                                   Style="{StaticResource BigWhite}"/>
                    </Button.Content>
                </Button>

                <Button Margin="10,0,0,0" 
                        Style="{StaticResource LoginButtons}"
                        Command="{x:Static ViewModels:SettingsPageViewModel.CancelNewItemCommand}">
                    <Button.Content>
                        <TextBlock Text="Cancel" 
                                   Style="{StaticResource BigWhite}"/>
                    </Button.Content>
                </Button>

            </StackPanel>

        </Grid>
        
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding ElementName=SelectedAction, Path=SelectedValue}" Value="CheckAfter">
                <Setter TargetName="WaitGrid" Property="Visibility" Value="Visible" />
            </DataTrigger>

            <DataTrigger Binding="{Binding ElementName=AlarmName, Path=Text}" Value="{x:Static System:String.Empty}">
                <Setter TargetName="SaveButton" Property="IsEnabled" Value="False" />
            </DataTrigger>
            
            <MultiDataTrigger>
                <MultiDataTrigger.Conditions>
                    <Condition Binding="{Binding ElementName=SelectedAction, Path=SelectedValue}" Value="CheckAfter" />
                    <Condition Binding="{Binding ElementName=WaitInterval, Path=Text}" Value="{x:Static System:String.Empty}" />
                </MultiDataTrigger.Conditions>
                
                <MultiDataTrigger.Setters>
                    <Setter TargetName="SaveButton" Property="IsEnabled" Value="False" />
                </MultiDataTrigger.Setters>
                
            </MultiDataTrigger>

        </DataTemplate.Triggers>
        
    </DataTemplate>

    <DataTemplate x:Key="ReadOnlyAlarmTemplate">
        <Grid HorizontalAlignment="Stretch">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <Grid Grid.Column="0"
                  HorizontalAlignment="Center"
                  VerticalAlignment="Center">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <TextBlock Style="{StaticResource BigWhite}"
                           Text="Type:"
                           VerticalAlignment="Center"
                           HorizontalAlignment="Right"
                           Margin="5" />

                <TextBox Style="{StaticResource LoginBox}"
                         VerticalAlignment="Center"
                         HorizontalAlignment="Left"
                         Margin="5"
                         Grid.Column="1"
                         Width="200"
                         x:Name="AlarmName"
                         Text="{Binding Path=Type}"
                         IsReadOnly="True"/>

            </Grid>

            <Grid Grid.Column="1"
                  HorizontalAlignment="Center"
                  VerticalAlignment="Center">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <TextBlock Style="{StaticResource BigWhite}"
                           Text="Level:"
                           VerticalAlignment="Center"
                           HorizontalAlignment="Right"
                           Margin="5" />

                <ComboBox ItemsSource="{Binding Source={StaticResource AlarmLevelProvider}}"
                          VerticalAlignment="Center"
                          HorizontalAlignment="Left"
                          Margin="5"
                          Grid.Column="1"
                          Height="25"
                          IsEditable="False"
                          IsSynchronizedWithCurrentItem="True"
                          IsTextSearchEnabled="True"
                          SelectedIndex="0"
                          Width="100"
                          SelectedItem="{Binding Path=Level, Mode=TwoWay}"/>

            </Grid>

            <Grid Grid.Column="2"
                  HorizontalAlignment="Center"
                  VerticalAlignment="Center">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <TextBlock Style="{StaticResource BigWhite}"
                           Text="Action:"
                           VerticalAlignment="Center"
                           HorizontalAlignment="Right"
                           Margin="5" />

                <ComboBox ItemsSource="{Binding Source={StaticResource AlarmActionProvider}}"
                          VerticalAlignment="Center"
                          HorizontalAlignment="Left"
                          Margin="5"
                          Grid.Column="1"
                          Height="25"
                          IsEditable="False"
                          IsSynchronizedWithCurrentItem="True"
                          IsTextSearchEnabled="True"
                          SelectedIndex="0"
                          x:Name="SelectedAction"
                          Width="100"
                          SelectedItem="{Binding Path=Action, Mode=TwoWay}"/>

            </Grid>

            <Grid Grid.Column="3"
                  HorizontalAlignment="Center"
                  VerticalAlignment="Center"
                  x:Name="WaitGrid"
                  Visibility="Collapsed">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <TextBlock Style="{StaticResource BigWhite}"
                           Text="Wait:"
                           VerticalAlignment="Center"
                           HorizontalAlignment="Right"
                           Margin="5" />

                <TextBox Style="{StaticResource LoginBox}"
                         VerticalAlignment="Center"
                         HorizontalAlignment="Left"
                         Margin="5"
                         Grid.Column="1"
                         Width="40"
                         x:Name="WaitInterval"
                         Text="{Binding Path=WaitInterval}"/>

            </Grid>

            <StackPanel Orientation="Horizontal"
                        Grid.Row="1"
                        Grid.ColumnSpan="4"
                        Margin="10,20,0,0"
                        VerticalAlignment="Center"
                        HorizontalAlignment="Center">

                <Button Margin="10,0,0,0" 
                        Style="{StaticResource LoginButtons}"
                        x:Name="SaveButton"
                        Command="{x:Static ViewModels:SettingsPageViewModel.SaveNewItemCommand}">
                    <Button.Content>
                        <TextBlock Text="Save" 
                                   Style="{StaticResource BigWhite}"/>
                    </Button.Content>
                </Button>

                <Button Margin="10,0,0,0" 
                        Style="{StaticResource LoginButtons}"
                        Command="{x:Static ViewModels:SettingsPageViewModel.CancelNewItemCommand}">
                    <Button.Content>
                        <TextBlock Text="Cancel" 
                                   Style="{StaticResource BigWhite}"/>
                    </Button.Content>
                </Button>

            </StackPanel>

        </Grid>

        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding ElementName=SelectedAction, Path=SelectedValue}" Value="CheckAfter">
                <Setter TargetName="WaitGrid" Property="Visibility" Value="Visible" />
            </DataTrigger>

            <DataTrigger Binding="{Binding ElementName=AlarmName, Path=Text}" Value="{x:Static System:String.Empty}">
                <Setter TargetName="SaveButton" Property="IsEnabled" Value="False" />
            </DataTrigger>

            <MultiDataTrigger>
                <MultiDataTrigger.Conditions>
                    <Condition Binding="{Binding ElementName=SelectedAction, Path=SelectedValue}" Value="CheckAfter" />
                    <Condition Binding="{Binding ElementName=WaitInterval, Path=Text}" Value="{x:Static System:String.Empty}" />
                </MultiDataTrigger.Conditions>

                <MultiDataTrigger.Setters>
                    <Setter TargetName="SaveButton" Property="IsEnabled" Value="False" />
                </MultiDataTrigger.Setters>

            </MultiDataTrigger>

        </DataTemplate.Triggers>

    </DataTemplate>

    <DataTemplate x:Key="AddAlarmPanelTemplate">
        <Border Background="{StaticResource MinOpacityBrush}"
                Height="100"
                Margin="0,10,0,0">
            <Grid>
                <Canvas Background="{StaticResource LineBrush}"
				        Height="1"
				        HorizontalAlignment="Stretch"
				        VerticalAlignment="Top"
				        Margin="2,0,2,0"/>
                
                <ContentControl VerticalAlignment="Center"
                                HorizontalAlignment="Center"
                                ContentTemplate="{StaticResource DefaultAlarmTemplate}"
                                Content="{Binding}"/>
            </Grid>

        </Border>        
    </DataTemplate>

    <DataTemplate x:Key="AddAlarmPanelROTemplate">
        <Border Background="{StaticResource MinOpacityBrush}"
                Height="100"
                Margin="0,10,0,0">
            <Grid>
                <Canvas Background="{StaticResource LineBrush}"
				        Height="1"
				        HorizontalAlignment="Stretch"
				        VerticalAlignment="Top"
				        Margin="2,0,2,0"/>

                <ContentControl VerticalAlignment="Center"
                                HorizontalAlignment="Center"
                                ContentTemplate="{StaticResource ReadOnlyAlarmTemplate}"
                                Content="{Binding}"/>
            </Grid>

        </Border>
    </DataTemplate>

</ResourceDictionary>